﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluentNHibernate.Mapping;

namespace Mindfor.Web.Modules.Catalog
{
	public class CategoryMap : ClassMap<Category>
	{
		public CategoryMap()
		{
			Table("ProductCategories");
			Id(m => m.Id);
			Map(m => m.Title).Length(255).Not.Nullable();
			Map(m => m.Picture).CustomSqlType("image").Length(int.MaxValue).Nullable();
			Map(m => m.Text).Nullable();
			Map(m => m.Sort).Not.Nullable();
			Map(m => m.ShowTiles).Nullable();

			References(m => m.Parent, "ParentId");
			HasMany<Category>(m => m.SubCategories).KeyColumn("ParentId").Inverse();
			HasMany<Product>(m => m.Products).KeyColumn("ProductCategoryId").Inverse();
		}
	}
}